package config

import (
	"common/helper"
	"database/sql"
)

//玩家累计充值奖励配置表

type CfgAccuDepositBonusItem struct {
	Level             int     `json:"level" db:"level" cbor:"level"`
	AccuDepositAmount float64 `json:"accu_deposit_amount" db:"accu_deposit_amount" cbor:"accu_deposit_amount"`
	Bonus             float64 `json:"bonus" db:"bonus" cbor:"bonus"`
}

type CsAccuDepositBonusCfg struct {
}

var cfgAccuDepositBonusList []CfgAccuDepositBonusItem

func (that *CsAccuDepositBonusCfg) GetCfg() []CfgAccuDepositBonusItem {
	return cfgAccuDepositBonusList
}

func AccuDepositBonusCfgSetRow(rows *sql.Rows) {
	var tVal CfgAccuDepositBonusItem
	var err error
	err = rows.Scan(&tVal.Level, &tVal.AccuDepositAmount, &tVal.Bonus)
	if err != nil {
		helper.InfoLog("AccuDepositBonusCfgSetRow scan err")
		return
	}

	cfgAccuDepositBonusList = append(cfgAccuDepositBonusList, tVal)
}

func AccuDepositBonusCfgRemove() {
	cfgAccuDepositBonusList = []CfgAccuDepositBonusItem{}
}

/*
根据累计充值额度获取对应的奖励值
*/
func GetBonusByAccuDeposit(accuDeposit float64) float64 {
	var bonus float64

	for Index := 0; Index < len(cfgAccuDepositBonusList); Index++ {
		if cfgAccuDepositBonusList[Index].AccuDepositAmount >= accuDeposit {
			bonus = cfgAccuDepositBonusList[Index].Bonus
			break
		}
	}

	return bonus
}

func GetBonusByStage(iStage int) float64 {
	var bonus float64

	for Index := 0; Index < len(cfgAccuDepositBonusList); Index++ {
		if cfgAccuDepositBonusList[Index].Level == iStage {
			bonus = cfgAccuDepositBonusList[Index].Bonus
			break
		}
	}

	return bonus
}

func GetBonusMaxLevelByAccuDeposit(accuDeposit float64) int {
	var level int

	for Index := 0; Index < len(cfgAccuDepositBonusList); Index++ {
		if cfgAccuDepositBonusList[Index].AccuDepositAmount <= accuDeposit {
			level = cfgAccuDepositBonusList[Index].Level
		}
	}

	return level
}
